# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgbase=libidn2
pkgname=('libidn2' 'libidn2-devel')
_basever=2.2.0
_subver=
pkgver=${_basever}${_subver}
pkgrel=1
pkgdesc="Implementation of the Stringprep, Punycode and IDNA specifications"
url="https://www.gnu.org/software/libidn/"
arch=('i686' 'x86_64')
license=('GPL3' 'LGPL')
makedepends=('gcc' 'make' 'pkg-config' 'texinfo' 'libunistring-devel')
options=('!libtool' 'staticlibs')
source=(https://ftp.gnu.org/gnu/libidn/${pkgname}-${pkgver}.tar.gz{,.sig}
        libidn2-2.1.0-msys2.patch)
sha256sums=('fc734732b506d878753ec6606982bf7b936e868c25c30ddb0d83f7d7056381fe'
            'SKIP'
            '971423372c3566ba08ba394231c91cac3be51bffd2d3a6b86c6301e8f977e11f')

prepare() {
  cd ${srcdir}/${pkgname}-${_basever}
  patch -p1 -i ${srcdir}/libidn2-2.1.0-msys2.patch

  autoreconf -ivf
}

build() {
  [[ -d ${srcdir}/build-${CHOST} ]] && rm -rf ${srcdir}/build-${CHOST}
  mkdir ${srcdir}/build-${CHOST}
  cd ${srcdir}/build-${CHOST}
  ../${pkgname}-${_basever}/configure \
    --prefix=/usr \
    --build=${CHOST} \
    --enable-shared \
    --enable-static
  make
  make DESTDIR=${srcdir}/dest-${CHOST} install
}

package_libidn2() {
  groups=('libraries')
  depends=('info' 'libunistring')
  install=libidn2.install

  mkdir -p ${pkgdir}/usr/bin
  cp -f ${srcdir}/dest-${CHOST}/usr/bin/*.dll ${pkgdir}/usr/bin/
  cp -rf ${srcdir}/dest-${CHOST}/usr/share ${pkgdir}/usr/
}

package_libidn2-devel() {
  pkgdesc="Libidn2 headers and libraries"
  groups=('development')
  depends=("libidn2=${pkgver}")

  mkdir -p ${pkgdir}/usr/bin
  cp -f ${srcdir}/dest-${CHOST}/usr/bin/*.exe ${pkgdir}/usr/bin/
  cp -rf ${srcdir}/dest-${CHOST}/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest-${CHOST}/usr/lib ${pkgdir}/usr/
}
